/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.tableTools;

import GUI.OptionsFrame;
import app.FrameController;
import java.awt.*;
import java.io.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author isen
 */
public class TableMaker extends javax.swing.JFrame {
  
    
    /**
     * Creates new form TableMaker
     */
    public TableMaker() {
        initComponents();        
        BoxLayout boxLayout = new BoxLayout(mainContent,BoxLayout.PAGE_AXIS);
        this.mainContent.setLayout(boxLayout);   
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
        this.setVisible(true); 
    }
    public TableMaker(File file) throws IOException {
        initComponents();        
        BoxLayout boxLayout = new BoxLayout(mainContent,BoxLayout.PAGE_AXIS);
        this.mainContent.setLayout(boxLayout);
        BufferedReader bReader = new BufferedReader(new FileReader(file));
        this.titre.setText(bReader.readLine().substring(8));
        this.sousTitre.setText(bReader.readLine().substring(8));
        this.lieu.setText(bReader.readLine().substring(8));
        
        while(bReader.ready()){
            System.out.println("reading coordinates line");
            String line = bReader.readLine();
            this.mainContent.add(new Row(line.substring(0, line.indexOf("\t")),line.substring(line.indexOf("\t")+1)));
            
        }
        
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
        this.setVisible(true); 
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        graphCanvas = new java.awt.Canvas(){

            @Override
            public void paint(Graphics g) {
                drawGraph(g);
                super.paint(g);
            }
        };
        graphPanel = new javax.swing.JPanel(){
            @Override
            protected void paintComponent(Graphics g){
                super.paintComponent(g);
                drawGraph(g);
                g.dispose();

            }

        };
        jPanel1 = new javax.swing.JPanel();
        mainScrollPane = new javax.swing.JScrollPane();
        mainContent = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        titre = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        sousTitre = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        lieu = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        deleteLine = new javax.swing.JButton();
        updatePreview = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        graphCanvas.setBackground(new java.awt.Color(255, 255, 255));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        graphPanel.setBackground(new java.awt.Color(255, 255, 255));
        graphPanel.setMaximumSize(new java.awt.Dimension(511, 560));
        graphPanel.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout mainContentLayout = new javax.swing.GroupLayout(mainContent);
        mainContent.setLayout(mainContentLayout);
        mainContentLayout.setHorizontalGroup(
            mainContentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 364, Short.MAX_VALUE)
        );
        mainContentLayout.setVerticalGroup(
            mainContentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 462, Short.MAX_VALUE)
        );

        mainScrollPane.setViewportView(mainContent);

        jLabel3.setText("titre:");

        jLabel5.setText("sous-titre:");

        jLabel6.setText("lieu:");

        jButton2.setText("OK");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel3)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(titre, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
                    .addComponent(sousTitre)
                    .addComponent(lieu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(titre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(sousTitre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(lieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel1.setText("distance");

        jLabel2.setText("altitude");

        jButton1.setText("+");
        jButton1.setToolTipText("Ajoute une ligne");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        deleteLine.setText("-");
        deleteLine.setToolTipText("Supprime la dernière ligne");
        deleteLine.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteLineActionPerformed(evt);
            }
        });

        updatePreview.setText("Preview");
        updatePreview.setToolTipText("<html>\nImporte des données sous la forme: <br>\ndistance (tabulation) hauteur <br>\netc... (maximum 100, <20 conseillé)");
        updatePreview.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                updatePreviewMouseClicked(evt);
            }
        });
        updatePreview.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updatePreviewActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jLabel1)
                .addGap(26, 26, 26)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteLine)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                .addComponent(updatePreview)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2)
                .addComponent(jLabel1)
                .addComponent(jButton1)
                .addComponent(deleteLine)
                .addComponent(updatePreview))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(mainScrollPane)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                .addContainerGap())
        );

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(graphPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 512, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(graphPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void updatePreviewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updatePreviewActionPerformed
       
        
    }//GEN-LAST:event_updatePreviewActionPerformed

    private void deleteLineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteLineActionPerformed
        this.mainContent.getComponent(mainContent.getComponentCount() - 1).setVisible(false);
        this.mainContent.remove(mainContent.getComponentCount() - 1);

        this.validate();
    }//GEN-LAST:event_deleteLineActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        mainContent.add(new Row());
        this.validate();
        //arrayContainer.add(Box.createRigidArea(null))

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if (!verify()) {
            return;
        }

        saveFile();

    }//GEN-LAST:event_jButton2ActionPerformed

    private void updatePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_updatePreviewMouseClicked
        this.graphPanel.repaint();
    }//GEN-LAST:event_updatePreviewMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TableMaker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TableMaker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TableMaker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TableMaker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TableMaker().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton deleteLine;
    private java.awt.Canvas graphCanvas;
    private javax.swing.JPanel graphPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField lieu;
    private javax.swing.JPanel mainContent;
    private javax.swing.JScrollPane mainScrollPane;
    private javax.swing.JTextField sousTitre;
    private javax.swing.JTextField titre;
    private javax.swing.JButton updatePreview;
    // End of variables declaration//GEN-END:variables

    private void saveFile() {
        JFileChooser chooser = new JFileChooser();
        chooser.setSelectedFile(new File(Preferences.systemNodeForPackage(FrameController.class).get("path", "C://Documents")+"//" +this.titre.getText()+".txt"));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.addChoosableFileFilter(new FileFilter() {

            @Override
            public boolean accept(File file) {
                String name = file.getName();
                
                if(!name.endsWith(".txt")){
                 System.out.println("illegal file format");
                 return false;
            }
                return true;
            }

            @Override
            public String getDescription() {
                return "*.txt files";
            }
        });
        
        int retour = chooser.showDialog(this, "choisir");
        if(retour == JFileChooser.APPROVE_OPTION){
            
             File file = chooser.getSelectedFile();
             Preferences.systemNodeForPackage(FrameController.class).put("path", file.getParent());
             System.out.println(file.getAbsolutePath());
             save(file);
             this.dispose();
        }
    }

    private void save(File file) {
        try {
            BufferedWriter bWriter = new BufferedWriter(new FileWriter(file));
            bWriter.write("titre1:\t"+this.titre.getText()+"\n");
            bWriter.write("titre2:\t"+this.sousTitre.getText()+"\n");
            bWriter.write("titre3:\t"+this.lieu.getText()+"\n");
            
            for (int i = 0; i<mainContent.getComponentCount();i++){
                bWriter.write(((Row)mainContent.getComponent(i)).getDistance()+"\t");
                bWriter.write(((Row)mainContent.getComponent(i)).getHauteur()+"\n");
                
            }
            bWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(TableMaker.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    
    public boolean verify(){
        int totalD = Integer.parseInt(((Row)mainContent.getComponent(mainContent.getComponentCount()-1)).getDistance())-Integer.parseInt(((Row)mainContent.getComponent(0)).getDistance());
        boolean erreurPente = false;
        boolean erreurDistance = false;
         for (int i = 0; i<mainContent.getComponentCount()-1;i++){
                int deltaH = Integer.parseInt(((Row)mainContent.getComponent(i+1)).getHauteur())-Integer.parseInt(((Row)mainContent.getComponent(i)).getHauteur());
                int deltaD = Integer.parseInt(((Row)mainContent.getComponent(i+1)).getDistance())-Integer.parseInt(((Row)mainContent.getComponent(i)).getDistance());
                if (deltaD <(totalD/20)){
                    erreurDistance = true;
                    ((Row)mainContent.getComponent(i+1)).setDistanceBg(Color.red);
                    
                } 
                if(((100*deltaH)/(deltaD))>20){
                    erreurPente = true;
                    
                    ((Row)mainContent.getComponent(i+1)).setHauteurBg(Color.red);
                    
                    
                }
               
            }
         String text = "";
                if (erreurDistance) text = text+ "La distance doit être toujours croissante,\n avec des points espacés de plus de 5% \nde la distance totale du parcours\n\n";
                if(erreurPente) text = text+ "La pente ne doit pas etre superieure à 20%, \n en montée comme en descente";
                
                if (!text.isEmpty()) {
                    JOptionPane.showMessageDialog(this,text);
                    return false;
                }
        return true;
    }
    
    
    
    public int verifyRowContent(Point loc){
        int values = 0;
        
        Row row = (Row)mainContent.getComponentAt(loc);
        int i = 0;
        while(!row.equals(mainContent.getComponent(i))){
            i++;
        }
        if(i == mainContent.getComponentCount()-1 || i == 0) return Row.CONTENT_OK;
        int totalD = Integer.parseInt(((Row)mainContent.getComponent(mainContent.getComponentCount()-1)).getDistance())-Integer.parseInt(((Row)mainContent.getComponent(0)).getDistance());
        
         int deltaH = Integer.parseInt(((Row)mainContent.getComponent(i+1)).getHauteur())-Integer.parseInt(((Row)mainContent.getComponent(i)).getHauteur());
         int deltaD = Integer.parseInt(((Row)mainContent.getComponent(i+1)).getDistance())-Integer.parseInt(((Row)mainContent.getComponent(i)).getDistance());
                if (deltaD <(totalD/20)){
                    values = values +Row.WRONG_DISTANCE;
                }
                if(((100*deltaH)/(deltaD))>20){
                    values = values +Row.WRONG_HAUTEUR;
                }
        return values;
    }
    
    private int getMaxHeight(){
        int max = Integer.parseInt(((Row)mainContent.getComponent(0)).getHauteur());
    
        for (int i = 0; i<mainContent.getComponentCount()-1;i++){
            int deltaH = Integer.parseInt(((Row)mainContent.getComponent(i+1)).getHauteur())-Integer.parseInt(((Row)mainContent.getComponent(i)).getHauteur());
            if (deltaH>0){
                max = Integer.parseInt(((Row)mainContent.getComponent(i+1)).getHauteur());
            }
        }
        return max;
        }
    
    private void drawGraph (Graphics g){
        Graphics2D g2 = (Graphics2D) g ;
if (mainContent.getComponentCount() <2){
            return;
        }
        
        System.out.println("redrawing panel");
        
        int xMax = ((Row)mainContent.getComponent(mainContent.getComponentCount()-1)).getIntDistance()
        -((Row)mainContent.getComponent(0)).getIntDistance();
        int yMax = getMaxHeight() ;
        
        int xRes = graphPanel.getWidth()-50;
        int yRes = graphPanel.getHeight() - 50;

        int xStart = 0 +25 ;//graphPanel.getX();
        int yStart = 0+ yRes + 25; //graphPanel.getY()+ yRes;
        g2.setStroke(new BasicStroke(3));
        g2.setColor(Color.BLACK);
        g2.drawLine(xStart, yStart, xStart, yStart-yRes);
        g2.drawLine(xStart, yStart, xStart+ xRes, yStart);
        int[] xp1 = {xStart,xStart+1,xStart-1}, yp1 = {yStart-yRes,yStart-yRes+2,yStart-yRes+2};
        int[] xp2 = { xStart+ xRes,xStart+ xRes-2,xStart+ xRes-2}, yp2 = {yStart,yStart+1,yStart-1};
        g2.drawPolygon(xp1, yp1, 3);
        g2.drawPolygon(xp2,yp2,3);
        g2.drawString(""+yMax, xStart-20, yStart-yRes-5);
        g2.drawString(""+xMax, xStart+xRes-10, yStart+20);
        g2.setStroke(new BasicStroke(2));
        g2.setColor(Color.BLUE);
        
        for (int i = 0; i<mainContent.getComponentCount()-1;i++){

            double x1 = (double)((Row)mainContent.getComponent(i)).getIntDistance();
            double y1 = (double)((Row)mainContent.getComponent(i)).getIntHauteur();
            double x2 = (double)((Row)mainContent.getComponent(i+1)).getIntDistance();
            double y2 = (double)((Row)mainContent.getComponent(i+1)).getIntHauteur();
            g2.drawLine( xStart + (int)((x1/xMax)*xRes),
                yStart - (int)((y1/yMax)*yRes),
                xStart + (int)((x2/xMax)*xRes),
                yStart - (int)((y2/yMax)*yRes)
            );
            /*System.out.println("drawing line : "+(xStart + (int)((x1/xMax)*xRes)) +",  "
                +(yStart - (int)((y1/yMax)*yRes)) +";  "
                +(xStart + (int)((x2/xMax)*xRes)) + ",  "
                +(yStart - (int)((y2/yMax)*yRes)));
            System.out.println("in bounds: "+xStart +",  "+(yStart) + ";  "+(xStart+xRes) +",  "+(yStart-yRes));
            * 
            */
        }
        //g.fillRect(xStart+1, yStart+1, 50, 50);
    }
}
